package com.open.capacity.service.impl;

import com.open.capacity.mapper.RegisterMapper;
import com.open.capacity.model.BusinessData;
import com.open.capacity.service.RegisterBusinessService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class RegisterBusinessServiceImpl implements RegisterBusinessService {
    @Autowired
    private RegisterMapper registerMapper;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Override
    public String add(BusinessData businessData) {
        businessData.setPasswd(DigestUtils.md5DigestAsHex(businessData.getPasswd().getBytes()));
        String result= registerMapper.add(businessData)== 1 ? "success" : "error";
        rabbitTemplate.convertAndSend("mailTopicExchange","send.a",businessData.getBemail());
        return result;
    }
}
